/*
 * @Description:用户状态管理
 */
import storageHelper from "@/libs/StorageHelper.js";
const state = {
  user_id: 0,
  token: "",
  username: "",
  referee_id: 0,
  vip: 0,
  gm: 0,
  mc: 0,
  phone: "",
  phone_state: 0,
  email: "",
  email_state: 0,
  login_ip: "",
  login_time: "",
  user_group: "",
  user_admin: "",
  signature: "",
  nickname: "",
  avatar: "/img/avatar.png",
  invite_code: "",
  friends: "",
  state: 0,
  userInfo:"",
};
const getters = {
  token(state) {
    return state.userInfo.token;
  },
  userName(state) {
    return state.userInfo.userName;
  },
  nickName(state) {
    return state.userInfo.nickName;
  },
};
const mutations = {
  setUserInfo(state, payload) {
    state.userInfo = payload;
    storageHelper.setUserInfo(payload);
  },
  user_set(state, payload) {
    storageHelper.setUserInfo(payload);
    for (var k in payload) {
      state[k] = payload[k];
    }
    if (payload.token) {
      storageHelper.setToken(payload.token);
      storageHelper.setGroupValue(payload.user_group);
    }
  },
  sign_out(state, payload) {
    storageHelper.delValue("userInfo");
    storageHelper.delValue("token");
    storageHelper.delValue("token");
    storageHelper.delValue("user_group");
    state.token = null;
    state.username = null;
    state.user_id = 0;
  },
};
const actions = {};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
